{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <select name="isexcel" lay-filter="isexcel">
                                <option value="1">搜索</option>
                                <option value="2">导出(信息较多时导出较慢)</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="province" data-area="" lay-filter="province">
                                <option value="">选择省</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="city" data-area="" lay-filter="city">
                                <option value="">选择市</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="area" data-area="" lay-filter="area">
                                <option value="">选择区</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="street" data-area="" lay-filter="street">
                                <option value="">选择街道</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="nickname" placeholder="用户昵称" value="{:input('get.nickname')}"
                                autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="mobile" placeholder="用户账号|身份证号" value="{:input('get.mobile')}"
                                autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="sreach">搜索|导出</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    共有数据：<strong id="count">{$list->total()}</strong> 条
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th><div class="layui-table-cell">ID</div></th>
                                <th><div class="layui-table-cell">用户信息</div></th>
                                <th><div class="layui-table-cell">头像</div></th>
                                <th><div class="layui-table-cell">身份证信息</div></th>
                                <!-- <th><div class="layui-table-cell">身份证正面</div></th>
                                <th><div class="layui-table-cell">身份证反面</div></th> -->
                                <th><div class="layui-table-cell">负责街道数量(不含审核中的)</div></th>
                                <th><div class="layui-table-cell">状态</div></th>
                                <th><div class="layui-table-cell">注册时间</div></th>
                                <th><div class="layui-table-cell">成单量</div></th>
                                <th><div class="layui-table-cell">成单金额</div></th>
                                <!-- <th><div class="layui-table-cell">成单重量</div></th> -->
                                <th><div class="layui-table-cell">邀请用户</div></th>
                                <th><div class="layui-table-cell">邀请订单</div></th>
                                <th><div class="layui-table-cell">操作</div></th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $list as $v}
                            <tr>
                                <td><div class="layui-table-cell">{$v.id|default='0'}</div></td>
                                <td><div class="layui-table-cell">手机:{$v.mobile|default=''}<br />
                                    微信昵称:{$v.nickname|default=''}</div></td>
                                <td><div class="layui-table-cell"><img onclick="showimg('{$v.logo|default=''}')" src="{$v.logo|default=''}" />
                                </div></td>
                                <td><div class="layui-table-cell">姓名:{$v.name|default=''}<br />身份证号:{$v.cards|default=''}</div></td>
                                <!-- <td><div class="layui-table-cell"><img onclick="showimg('{$v.positive|default=''}')" src="{$v.positive|default=''}" />
                                </div></td>
                                <td><div class="layui-table-cell"><img onclick="showimg('{$v.negative|default=''}')" src="{$v.negative|default=''}" />
                                </div></td> -->
                                <td><div class="layui-table-cell"><a title="负责街道"
                                        onclick="data_edit('负责街道','/garbag/rider_street?mobile={$v.mobile}&otrue=1')"
                                        href="javascript:;" class="layui-btn layui-btn-sm layui-bg-black">{$v.streets}</a>
                                    <a title="添加街道" onclick="data_edit('添加街道','/garbag/street_add?id={$v.id}')"
                                        href="javascript:;" class="layui-btn layui-btn-sm layui-btn layui-btn-sm-normal">
                                        添加街道
                                    </a>
                                </div></td>
                                <td><div class="layui-table-cell">{if $v.status == 1}正常{elseif $v.status == 2}忙碌{else}下线{/if}</div></td>
                                <td><div class="layui-table-cell">{$v.created}</div></td>
                                <td><div class="layui-table-cell"><a title="完成订单" onclick="data_edit('完成订单','/garbag/order?cmobile={$v.id}&status=4')"
                                        href="javascript:;"
                                        class="layui-btn layui-btn-sm layui-bg-cyan">总单:{$v.order|default='0'}</a><br />
                                    <a title="今日完成订单"
                                        onclick="data_edit('今日完成订单','/garbag/order?cmobile={$v.id}&status=4&starttime={:date(\'Y-m-d 00:00:00\',time())}&endtime={:date(\'Y-m-d 00:00:00\',time()+86400)}')"
                                        href="javascript:;" class="layui-btn layui-btn-sm">日单:{$v.todayorder|default='0'}</a>
                                </div></td>
                                <td><div class="layui-table-cell"><a title="完成总额" onclick="data_edit('完成总额','/garbag/order?cmobile={$v.id}&status=4')"
                                        href="javascript:;"
                                        class="layui-btn layui-btn-sm layui-bg-cyan">总额:{$v.total|default='0'}元</a><br /><a
                                        title="今日完成总额"
                                        onclick="data_edit('今日完成总额','/garbag/order?cmobile={$v.id}&status=4&starttime={:date(\'Y-m-d 00:00:00\',time())}&endtime={:date(\'Y-m-d 00:00:00\',time()+86400)}')"
                                        href="javascript:;" class="layui-btn layui-btn-sm">日额：{$v.todaytotal|default='0'}元</a>
                                </div></td>
                                <!-- <td><div class="layui-table-cell"><a title="完成总重" onclick="data_edit('完成总重','/garbag/order?cmobile={$v.id}&status=3')"
                                        href="javascript:;"
                                        class="layui-btn layui-btn-sm layui-bg-cyan">总重：{$v.weight|default='0'}公斤</a><br />
                                    <a title="今日完成总重"
                                        onclick="data_edit('今日完成总重','/garbag/order?cmobile={$v.id}&status=3&starttime={:date(\'Y-m-d 00:00:00\',time())}&endtime={:date(\'Y-m-d 00:00:00\',time()+86400)}')"
                                        href="javascript:;" class="layui-btn layui-btn-sm">日重:{$v.todayweight|default='0'}公斤</a>
                                </div></td> -->
                                <td><div class="layui-table-cell"><a title="邀请用户" onclick="data_edit('邀请用户','/garbag/user?pid={$v.user_id}')"
                                        href="javascript:;"
                                        class="layui-btn layui-btn-sm layui-bg-cyan">人数：{$v.tjcount|default='0'}人</a></div></td>
                                <td><div class="layui-table-cell">
                                    <a title="邀请订单" onclick="data_edit('邀请订单明细','/garbag/order?pid={$v.user_id}')"
                                        href="javascript:;"
                                        class="layui-btn layui-btn-sm layui-bg-cyan">推荐订单：{$v.tjocount|default='0'}单，推荐总额：{$v.tjototal|default='0'}人</a>
                                </div></td>
                                <td><div class="layui-table-cell">
                                    <a title="修改密码" onclick="data_edit('修改密码','/garbag/rider_edit?id={$v.id}')"
                                        href="javascript:;" class="layui-btn layui-btn-sm layui-btn layui-btn-sm-normal">
                                        修改密码
                                    </a>
                                    <a title="查看位置"
                                        onclick="data_edit('查看位置','/garbag/rider_area?lat={$v.riderlat}&lon={$v.riderlon}')"
                                        href="javascript:;" class="layui-btn layui-btn-sm layui-bg-cyan">查看位置</a>
                                    <a title="删除家政" onclick="orderstr('确定删除吗？','/garbag/rider_del','{$v.id}',4)"
                                        href="javascript:;" class="layui-btn layui-btn-sm-danger layui-btn layui-btn-sm">
                                        删除家政
                                    </a>
                                </div></td>
                            </tr>
                            {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$list->render()|raw}
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
            , upload = layui.upload;
        //渲染省份
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 1 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择省份</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.area_code;
                        if (res.type != 1) {
                            if (obj.area_code == res.province) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.area_code == res.province) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="province"]').html(str);
                    form.render();
                }
            }
        });
        //选软城市
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 2 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择城市</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.area_code;
                        if (res.type != 1) {
                            if (obj.area_code == res.city) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.area_code == res.city) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="city"]').html(str);
                    form.render();
                }
            }
        });
        //选软区域
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 3 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择区域</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.area_code;
                        if (res.type == 3) {
                            if (obj.area_code == res.area && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.area_code == res.area && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="area"]').html(str);
                    form.render();
                }
            }
        });
        //选软街道
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 4 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择街道|村镇</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.id;
                        if (res.type == 4) {
                            if (obj.id == res.street && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.id == res.street && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="street"]').html(str);
                    form.render();
                }
            }
        });
        //监听省份选择市区
        form.on('select(province)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 2 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择城市</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="city"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });

        form.on('select(city)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 3 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择区域</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="area"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });
        form.on('select(area)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 4 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择街道|村镇</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.id;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="street"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });
        //图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: 'users_top'
            , accept: 'file'
            , exts: 'xls|csv'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.status > 0) {
                    return layer.msg(res.msg);
                }
                //上传成功
                return layer.msg(res.msg);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-sm layui-btn layui-btn-sm-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
    function showimg(imgs) {
        console.log(imgs);
        layer.open({
            type: 1,
            title: false,
            shadeClose: true,
            skin: 'layui-layer-nobg', //没有背景色
            content: "<img src='" + imgs + "' style='width:100%;height: 100%;'>"
        });
    }
    function orderstr(title, url, id, status) {
        if (status == 2) {
            layer.prompt({ title: '填写家政手机号码' }, function (value, index, elem) {
                $.post(url, { id: id, status: status, mobile: value }, function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                        location.replace(location.href);
                    } else {
                        layer.msg(data.msg, { icon: 2, time: 1000 });
                    }
                });
                layer.close(index);
            });
        } else {
            layer.confirm(title, { title: '请谨慎操作' }, function (index) {
                $.post(url, { id: id, status: status }, function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                        location.replace(location.href);
                    } else {
                        layer.msg(data.msg, { icon: 2, time: 1000 });
                    }
                });
            });
        }

    }
</script>
{include file="public/footer"}